package com.example.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.mapper.CameraMapper;
import com.example.mapper.LamppostMapper;
import com.example.model.Camera;
import com.example.model.CameraLamCount;
import com.example.model.Lamppost;
import com.example.service.CameraLamCountService;

@RestController
public class DemoContriller {
	
	@Autowired
	private CameraLamCountService cameraLamCountService;
	@Autowired
	private LamppostMapper lamppostMapper;
	@Autowired
	private CameraMapper cameraMapper;
	
	@RequestMapping(value = "/syn" ,method = RequestMethod.GET)
	public void synCameraAndPost() {
		
		List<CameraLamCount> cameraLamCountList = cameraLamCountService.select();
		for (CameraLamCount demo : cameraLamCountList) {
			if(demo.getCount()==1) {
				break;
			}
			Double latitude= demo.getLatitude();
			Double longtude= demo.getLongitude();
			if(demo.getCode()==null) {
				Integer id = demo.getId();
			    String name = demo.getCameraName();
				
				//加灯杆
				Lamppost la = new Lamppost();
				la.setCode("P"+id.toString());
				la.setName(name+la.getCode());
				la.setDescription(la.getName()+"灯杆");
				la.setLatitude(latitude);
				la.setLongitude(longtude);
				la.setOrgid(66L);
				la.setType("6");
				lamppostMapper.insertSelective(la);
				System.out.println("增加灯杆"+la.getName());
			}
			//改camera数据
			Camera record = new Camera();
			record.setLatitude(latitude);
			record.setLongitude(longtude);
			
			cameraMapper.updateByPosition(record);
		}
		System.out.println("同步完成");
	}
	
	

}
